def get_table_info_sql(database_type, source):
    v_sql = ""
    if database_type == 'openGauss' or database_type == 'gaussdb':
        v_sql = """
        select ''""" + source + """'' as source
              ,(case
                 when substr(version(), 0, 1) = ''(''
                   then substring(substr(version(), 2, length(version())) from ''^[^ ]+'')
                 else substring(version() from ''^[^ ]+'')
               end)::text as database_type
           ,ic.table_schema::text as schema
              ,o.owner::text
           ,ic.table_name::text
              ,regexp_replace(tab_com.description::text,E''\\x1F'','''', ''g'') as table_comment
              ,ic.ordinal_position::text as column_num
              ,ic.column_name::text
              ,(case
                 when ic.data_type = ''bigint''
                   then ''INT8''
             when ic.data_type = ''integer''
               then ''INT4''
             when ic.data_type = ''smallint''
               then ''INT2''
                 when ic.data_type in (''nvarchar2'') AND ic.character_maximum_length IS NOT NULL
                   then upper(ic.data_type) || ''('' || ic.character_maximum_length || '')''
             when ic.data_type in (''nvarchar2'') AND ic.character_maximum_length IS NULL
                   then ''NVARCHAR2''
                 when ic.data_type in (''character varying'')
                   then ''VARCHAR('' || ic.character_maximum_length || '')''
              when ic.data_type in (''character'')
               then ''CHAR('' || ic.character_maximum_length || '')''
                 when ic.data_type = ''timestamp without time zone''
                   then ''TIMESTAMP('' || ic.datetime_precision || '')''
                 when ic.data_type = ''time without time zone''
                   then ''TIME('' || ic.datetime_precision || '')''
                 when ic.data_type = ''numeric'' and ic.numeric_precision is not null and ic.numeric_scale is not null
                   then ''NUMERIC('' || ic.numeric_precision || '','' || ic.numeric_scale || '')''
             when ic.data_type = ''numeric'' and ic.numeric_precision is null and ic.numeric_scale is null
                   then ''NUMERIC''
                 when ic.data_type = ''text''
                   then ''TEXT''
                 when ic.data_type = ''date''
                   then ''DATE''
                 else upper(ic.data_type)
               end)::text as data_type
              ,(CASE
                 when (POSITION(lower(''::regclass'') IN lower(ic.column_default)) > 0)
                   then REPLACE(ic.column_default, ''::regclass'', '''')
                 when (POSITION(lower(''::integer'') IN lower(ic.column_default)) > 0)
                   then REPLACE(REPLACE(ic.column_default, ''::integer'', ''''), '''''''', '''')
                 else ic.column_default
               end)::text as data_default
              ,ic.is_nullable::text as nullable
              ,(case
                 when pc.conname is null then null::text
                 else ''Y''
               end)::text as pkey
             ,regexp_replace(col_com.description::text,E''\\x1F'','''', ''g'') as column_comment
         from pg_class c
          join adm_objects o 
           on o.object_id = c.oid and o.object_type like ''%table%''
          and c.relkind in (''r'',''p'')
          join pg_namespace n
            on c.relnamespace = n.oid
          join information_schema.columns ic
           on ic.table_name = c.relname
          and n.nspname = ic.table_schema
          left join pg_description tab_com
            on tab_com.objoid = c.oid
           and tab_com.objsubid = 0
          left join pg_description col_com
            on col_com.objoid = c.oid
           and col_com.objsubid = ic.ordinal_position
          left join (
            SELECT conname, conrelid , unnest(conkey) as column_num
              FROM pg_constraint
             where contype = ''p'') as pc
            on pc.conrelid = c.oid
           and pc.column_num = ic.ordinal_position
         where 1=1
           -- and ic.table_schema in ( ''fin_company_account'' )
           and ic.table_schema !~* ''pg_catalog|adms_checkpoint''
           and o.owner !~* ''rdsAdmin|adms_checkpoint''
         order by ic.table_schema, ic.table_name, ic.ordinal_position"""
        # print("")
    elif database_type == 'PostgreSQL':
        v_sql = """
        with tab_info_v as (
          SELECT ''""" + source + """'' as source
                ,substring(version() FROM ''(\S+)'') as database_type
                ,n.nspname AS schema
                ,r.rolname as owner
                ,c.relname AS table_name
                ,(col_description(c.oid, 0))::character varying AS table_comment
                ,a.attnum as column_num
                ,a.attname AS column_name
                ,concat_ws('''', t.typname) AS data_type
                ,(CASE
                   WHEN a.attlen > 0 THEN a.attlen
                   WHEN t.typname = ''bit'' THEN a.atttypmod
                   ELSE a.atttypmod - 4
                  END) AS data_length
                ,CASE
                  -- 为了和 高斯比对
                   WHEN (((format_type(a.atttypid, a.atttypmod))::character varying)::text = ''date''::text) THEN ''TIMESTAMP(0)''::character varying
                   WHEN (((format_type(a.atttypid, a.atttypmod))::character varying)::text = ''bigint''::text) THEN ''INT8''::character varying
                   WHEN (((format_type(a.atttypid, a.atttypmod))::character varying)::text = ''smallint''::text) THEN ''INT2''::character varying
                   WHEN (((format_type(a.atttypid, a.atttypmod))::character varying)::text = ''integer''::text) THEN ''INT4''::character varying
                   WHEN (left(((format_type(a.atttypid, a.atttypmod))::character varying)::text, 17) = ''character varying''::text) THEN (replace(((format_type(a.atttypid, a.atttypmod))::character varying)::text, ''character varying''::text, ''VARCHAR''::text))::character varying
                   WHEN (left(((format_type(a.atttypid, a.atttypmod))::character varying)::text, 9) = ''character''::text) THEN (replace(((format_type(a.atttypid, a.atttypmod))::character varying)::text, ''character''::text, ''char''::text))::character varying
                   WHEN (((format_type(a.atttypid, a.atttypmod))::text)::text = ''timestamp without time zone''::text) THEN ''TIMESTAMP''::character varying
                   WHEN (((format_type(a.atttypid, a.atttypmod))::text)::text = ''timestamp(0) without time zone''::text) THEN ''TIMESTAMP(0)''::character varying
                   WHEN (((format_type(a.atttypid, a.atttypmod))::text)::text = ''timestamp(6) without time zone''::text) THEN ''TIMESTAMP(6)''::character varying
                   ELSE (format_type(a.atttypid, a.atttypmod))::character varying
                 END AS typelen
                ,(CASE
                    WHEN a.attnotnull = TRUE THEN ''NO''
                    ELSE ''YES''
                  END) AS is_nullable  --  可为空
                ,(CASE
                    WHEN (SELECT COUNT(pg_constraint.*)
                            FROM pg_constraint
                           INNER JOIN pg_class
                              ON pg_constraint.conrelid = pg_class.oid
                           INNER JOIN pg_attribute
                              ON pg_attribute.attrelid = pg_class.oid
                             AND pg_attribute.attnum = ANY(pg_constraint.conkey)
                           INNER JOIN pg_type
                              ON pg_type.oid = pg_attribute.atttypid
                           WHERE pg_class.relname = c.relname
                             AND pg_constraint.contype = ''p''
                             AND pg_attribute.attname = a.attname
                             and pg_class.relowner = c.relowner
                             ) > 0 THEN ''Y''
                    ELSE NULL
                  END) AS pkey
                ,pg_get_expr(ad.adbin, ad.adrelid) as data_default
                ,(SELECT description
                    FROM pg_description
                   WHERE objoid = a.attrelid
                     AND objsubid = a.attnum) AS column_comment
            FROM pg_class c
           inner join pg_roles r
              on c.relowner = r.oid
             and c.relkind in (''r'',''p'')
             and c.relpartbound is null
                 -- and ((relkind = ''p'') or (relkind = ''r'' and relpartbound is null))
           inner join pg_attribute a
              on a.attnum > 0
             AND a.attrelid = c.oid
           inner join pg_namespace n
              on n.oid = c.relnamespace
           inner join pg_type t
              on a.atttypid = t.oid
            left join pg_attrdef ad  --  列的默认值
              on ad.adrelid = c.oid
             and ad.adnum = a.attnum
           WHERE 1 = 1
             and n.nspname not in (''information_schema'')
           ORDER BY c.relname ASC
                   ,a.attnum ASC
                   ,a.attname ASC
        )
        select source
              ,database_type
              -- ,schema
              ,CASE schema
                 when ''tzq'' then ''f_g_tzq''
                 else schema
               END as schema
              ,CASE owner
                 when ''tzq'' then ''f_g_tzq''
                 else schema
               END as owner
              ,table_name, table_comment
              ,column_num
              ,column_name
              ,replace(upper(typelen),''VARCHAR'',''NVARCHAR2'') as data_type
              ,data_default as data_default
              ,is_nullable as nullable
              ,pkey
              ,column_comment
          from tab_info_v v
         where 1=1
           and table_name not like ''adms_ogg_checkpoint%''
           and schema !~* ''pg_catalog''
         order by schema, table_name, column_num, column_name"""
    else:
        print("get_table_info_services.py -- 未知的数据库类型！")
    return v_sql
